package com.example.bookManagement.Aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeAspect {
    @Around("execution(* com.example.bookManagement.Controller.*.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录开始时间
        long startTime = System.currentTimeMillis();
        //执行原始方法
        Object result = joinPoint.proceed();
        //记录方法执行时间
        long endTime = System.currentTimeMillis();
        long elapsedTime = endTime - startTime;
        log.info(joinPoint.getSignature()+"耗时: {} ms", elapsedTime);
        return result;
    }
}
